package com.jia.springcloud.controller;

import com.jia.springcloud.entities.Payment;
import com.jia.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 1038940655
 * @create 2021/1/21 23:13
 */

@RestController
@Slf4j
public class PaymentHystrixController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

//服务降级
    @RequestMapping("/payment/hystrix/ok/{id}")
    public Payment getPaymentById(@PathVariable("id") Integer id){

        Payment payment = paymentService.getPaymentById(id);
        log.info("****result："+payment);
        return payment;
    }

    @RequestMapping("/payment/hystrix/timeout")
    public String paymentInfo_TimeOut(){

        String result = paymentService.paymentInfo_TimeOut();
        log.info("***result:"+result);
        return result;
    }


//服务熔断
//===服务熔断
@GetMapping("/payment/circuit/{id}")
public String paymentCircuitBreaker(@PathVariable("id") Integer id){
    String result = paymentService.paymentCircuitBreaker(id);
    log.info("*******result:"+result);
    return result;
}


}
